<?php
class gearController extends base
{

    public function __construct($type='api')
    {
        parent::__construct($type);
    }
    /**
     * 装备主页
     */
    public function dogearHome()
    {
    	$uid = $this->uid;
    	$homeRec = $this->load('gear')->homeRecGear();
    	$brandList = $this->load('gear')->getBrandList();
        if($brandList)
        {
            foreach ($brandList as & $v) {
                unset($v['sorder'], $v['isShow']);
            }
        }
    	$mayLike = $this->load('gear')->mayLike($uid);
    	$this->result['result'] = compact('homeRec','brandList','mayLike');
    }
    /**
     * 装备属性
     */
    public function doattrs()
    {
        $shoeAttr = common::$shoeAttr;
        $shoeAttrName = common::$shoeAttrName;
        $result = array();
        $attr = array();
        foreach ($shoeAttr as $attrField => $v) {
            $value = array('attrField' => $attrField,
                           'attrName'  => $shoeAttrName[$attrField]
                );
            foreach ($v as $key => $name) {
               $value['valueList'][] = array('value' => $key, 'name' => $name);
            }
            $attr[] = $value;
            unset($value);
        }
        $price = array(array('min' => 0, 'max' => 500),
                       array('min' => 500, 'max' => 799),
                       array('min' => 800, 'max' => 999),
                       array('min' => 1000, 'max' => 1999),
                       array('min' => 2000, 'max' => ''),
                );
        $this->result['result'] = compact('attr', 'price');
    }
    /**
     * 品牌下装备列表
     */
    public function dobrandGearList()
    {
        $brandId = common::request('brandId', 'G');
        $gearId = common::request('gearId', 'G',0);
        $offset = common::request('offset', 'G',20);
        $sortType = common::request('sortType', 'G', 4);
        if(empty($brandId))
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        switch ($sortType) {
            case 1:
                $sort = 'price';
                $order = 'DESC';
                break;
            case 2:
                $sort = 'price';
                $order = 'ASC';
                break;
            case 3:
                $sort = 'likes';
                $order = 'DESC';
                break;
            default:
                $sort = 'publishTime';
                $order = 'DESC';
                break;
        }
        $brandId = intval($brandId);
        $gearId <= 0 && $gearId = 0;
        $gearList = $this->load('gear')->gearListByBrand($brandId, $gearId, $offset, $sort, $order);
        $this->result['result'] = $gearList;
    }
    /**
     * 推荐装备列表
     */
    public function dorecGearList()
    {
        $tid = common::request('tid', 'G');
        $gearId = common::request('gearId', 'G',0);
        $offset = common::request('offset', 'G',20);
        $sortType = common::request('sortType', 'G', 4);
        if(empty($tid))
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        switch ($sortType) {
            case 1:
                $sort = 'price';
                $order = 'DESC';
                break;
            case 2:
                $sort = 'price';
                $order = 'ASC';
                break;
            case 3:
                $sort = 'likes';
                $order = 'DESC';
                break;
            default:
                $sort = 'publishTime';
                $order = 'DESC';
                break;
        }
        $tid = intval($tid);
        $gearId <= 0 && $gearId = 0;
        $gearList = $this->load('gear')->gearListByRec($tid, $gearId, $offset, $sort, $order);
        $this->result['result'] = $gearList;
    }
    /**
     * 关键词搜索跑鞋
     */
    public function dosearchGearbyKw()
    {
    	$keywords = common::request('keywords', 'G');

        $gender = common::request('gender', 'G',0);
        $feature = common::request('feature', 'G',0); // 功能
        $shoeCat = common::request('shoeCat', 'G',0); // 类别
        $minPrice = common::request('minPrice', 'G', 0);
        $maxPrice = common::request('maxPrice', 'G', 0);
        $brand = common::request('brand', 'G', 0);
        $score = common::request('gearScore');
        $publishTime = common::request('gearYear');

    	$gearId = common::request('gearId', 'G',0);
    	$offset = common::request('offset', 'G',20);
    	$sortType = common::request('sortType', 'G', 4);
 		switch ($sortType) {
 			case 1:
 				$sort = 'price';
 				$order = 'DESC';
 				break;
 			case 2:
 				$sort = 'price';
 				$order = 'ASC';
 				break;
 			case 3:
 				$sort = 'likes';
 				$order = 'DESC';
 				break;
 			default:
 				$sort = 'publishTime';
 				$order = 'DESC';
 				break;
 		}
 		$gearId <= 0 && $gearId = 0;
        $attrFilter = compact('gender','feature','shoeCat','minPrice','maxPrice','brand','publishTime','socre');
 		$gearList = $this->load('gear')->gearListBykeywords($keywords,$attrFilter, $gearId, $offset, $sort, $order);
    	$this->result['result'] = $gearList;
    }
    /**
    *没完成
    *2.5改版筛选
    */
    public function dosearchGear25()
    {
        $gearScore =(int)common::request('gearScore', 'G', 0); 
        $gearYear  =common::request('gearYear ', 'G', 0); 
        $minPrice = common::request('minPrice', 'G', 0);
        $maxPrice = common::request('maxPrice', 'G', 1000000);
        $brand = common::request('brand', 'G', 0);

        $p = common::request('p', 'G',1);
        $offset = common::request('offset', 'G',10);
        $sortType = common::request('sortType', 'G', 4);
        switch ($sortType) {
            case 1:
                $sort = 'price DESC';
                break;
            case 2:
                $sort = 'price ASC';            
                break;
            case 3:
                $sort = 'likes DESC';           
                break;
            default:
                $sort = 'addTime DESC';       
                break;
        }

        $sql="SELECT gearId,name,price,currency,likes,possess,comments,images,score FROM r_gear where price BETWEEN {$minPrice} AND {$maxPrice} ";
        if( $gearScore){
            $sql.=" AND score BETWEEN {$gearScore} AND ".($gearScore+0.9);
        }
        if( $gearYear){
            $sql.=" AND YEAR(addTime)={$gearYear} ";
        }
        if($brand){
            $sql.=" AND brand={$brand} ";
        }
        $sql.= " ORDER BY {$sort} LIMIT ".($p-1)*$offset.",{$offset}";

        $list=$this->db->getAll($sql);
        foreach($list as $k=>$v){
             $tmp=json_decode($v['images'],true);
            if(!empty($tmp)){ 
                $list[$k]['images']=$tmp[0];
            }else{
                $list[$k]['images']='';
            }
        }     
        $this->result['result']=$list;
       common::pr($this->result);
    }


    /**
     * 选鞋工具
     */
    public function doshoeSelectTool(){
        if($this->afterVersion('2.8.1', '2.8.1')){
            $this->_shoeSelectTool28();
        }else{
            $this->_shoeSelectTool27();
        }
    }
    
    public function _shoeSelectTool28(){
    	$height = common::request('height', 'G');
    	$weight = common::request('weight', 'G');
    	$runPlace = common::request('runPlace', 'G', '');
    	$footCircle = common::request('footCircle', 'G', ''); // 适合足类
    	$footType = common::request('footType', 'G', ''); // 足型
    	$isHurt = common::request('healthy', 'G', 0);

        $gender = common::request('gender', 'G',1);
        $feature = common::request('feature', 'G',0); // 功能
        $shoeCat = common::request('shoeCat', 'G',0); // 类别
        $minPrice = common::request('minPrice', 'G', 0);
        $maxPrice = common::request('maxPrice', 'G', 0);
        $brand = common::request('brand', 'G', 0);

    	$gearId = common::request('gearId', 'G',0);
    	$offset = common::request('offset', 'G',20);
    	$sortType = common::request('sortType', 'G', 4);
        $sync = common::request('sync','G',1);

        $gearId <= 0 && $gearId = 0;
        $attrFilter = compact('gender','feature','shoeCat','minPrice','maxPrice','brand');
        if ($this->uid) {
            $is_defaultData = $this->db->getOne('select is_defaultData from r_user where uid=' . $this->uid);
            if($sync || $is_defaultData == 1){
                $userData = [
                    'gender'            => $gender,
                    'height'            => $height,
                    'weight'            => $weight,
                    'is_defaultData'    => 2
                ];
                $this->load('client')->setUserInfo($this->uid,$userData);
            }
        }
        $result = [];
        $gear_mod = $this->load('gear');
        //最实惠（最低价）
        $price = $gear_mod->getOneShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, 'price', 'ASC');
        if($price){
            $price['title'] = '最实惠';
            $result[0] = $price;
        }
        //最多人拥有
        $possess = $gear_mod->getOneShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, 'possess', 'DESC');
        if($possess){
            $possess['title'] = '最多人拥有';
            $result[3] = $possess;
        }
        //最多人想要
        $like = $gear_mod->getOneShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, 'likes', 'DESC');
        if($like){
            $like['title'] = '最多人想要';
            $result[4] = $like;
        }
        //顶级款
        $attrFilter['level'] = 1;
        $level = $gear_mod->getOneShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, 'publishTime', 'DESC');
        if($level){
            $level['title'] = '顶级款';
            $result[1] = $level;
        }
        //次顶级
        $attrFilter['level'] = 2;
        $level2 = $gear_mod->getOneShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, 'publishTime', 'DESC');
        if($level2){
            $level2['title'] = '次顶级';
            $result[2] = $level2;
        }
        
        ksort($result);
        $this->result['result'] = array_values($result);
    }
    
    public function _shoeSelectTool27()
    {
    	$height = common::request('height', 'G');
    	$weight = common::request('weight', 'G');
    	$runPlace = common::request('runPlace', 'G', '');
    	$footCircle = common::request('footCircle', 'G', ''); // 适合足类
    	$footType = common::request('footType', 'G', ''); // 足型
    	$isHurt = common::request('healthy', 'G', 0);

        $gender = common::request('gender', 'G',1);
        $feature = common::request('feature', 'G',0); // 功能
        $shoeCat = common::request('shoeCat', 'G',0); // 类别
        $minPrice = common::request('minPrice', 'G', 0);
        $maxPrice = common::request('maxPrice', 'G', 0);
        $brand = common::request('brand', 'G', 0);

    	$gearId = common::request('gearId', 'G',0);
    	$offset = common::request('offset', 'G',20);
    	$sortType = common::request('sortType', 'G', 4);
        $sync = common::request('sync','G',1);

    	switch ($sortType) {
 			case 1:
 				$sort = 'price';
 				$order = 'DESC';
 				break;
 			case 2:
 				$sort = 'price';
 				$order = 'ASC';
 				break;
 			case 3:
 				$sort = 'likes';
 				$order = 'DESC';
 				break;
 			default:
 				$sort = 'publishTime';
 				$order = 'DESC';
 				break;
 		}
    	$gearId <= 0 && $gearId = 0;
        $attrFilter = compact('gender','feature','shoeCat','minPrice','maxPrice','brand');
        if ($this->uid) {
            $is_defaultData = $this->db->getOne('select is_defaultData from r_user where uid=' . $this->uid);
            if($sync || $is_defaultData == 1){
                $userData = [
                    'gender'            => $gender,
                    'height'            => $height,
                    'weight'            => $weight,
                    'is_defaultData'    => 2
                ];
                $this->load('client')->setUserInfo($this->uid,$userData);
            }
        }
 		$gearList = $this->load('gear')->getShoeUseSt($height,$weight, $runPlace,$footCircle, $footType, $isHurt,$attrFilter, $gearId, $offset, $sort, $order);

    	$this->result['result'] = $gearList;
    }
    /**
     * 热门搜索词
     */
    public function doserchRecGear()
    {
        $this->result['result'] = $this->load('gear')->searchRecList();
    }
    /**
     * 装备详情
    */
    public function dogearInfo()
    {
    	$gearId = common::request("gearId", 'G');
    	$gearInfo = $this->load('gear')->getGearInfo($gearId);
    	if(empty($gearInfo) || $gearInfo['isShow'] != 1)
    	{
    		$_ENV['error']->getErrors(1000);
    		exit;
    	}
        $this->load('gear')->incrViewCounts($gearId);
    	$result = array('gearId' => $gearId,
    					'name'	=> $gearInfo['name'],
    					'shareContent'	=> '',
    					'shareImg'	=> empty($gearInfo['images']) ? '' : $gearInfo['images'][0],
                        'webUrl'    => 'http://'.$this->config['host'].'/shoe/'.$gearId.'.html',
    					'images'	=> $gearInfo['images'],
                        'viewCounts'=> ++$gearInfo['viewCounts']
    				);
    	$this->result['result'] = $result;
    }

    /**
     *合辑详情
     */
    public function dogetSetInfo()
    {
        $sid = common::request('sid');
        $gearSet = $this->load('gear')->getGearSetInfoByGid($sid);
        $this->load('gear')->incrViewCounts($sid);

        if(empty($gearSet))
        {
            $_ENV['error']->getErrors(1000);
            exit;
        }

        $this->result['result'] = array(
            'sid' => $sid,
            'name' => $gearSet['name'],
            'shareContent' => $gearSet['shortDesc'],
            'shareImg' => $gearSet['img'],
            'webUrl' => 'http://'.$this->config['host'].'/show/gearSet?sid=' . $sid,
            'images' => json_decode($gearSet['images'], TRUE),
            'likes'=> $gearSet['likes'],
            'viewCounts'=> ++$gearSet['viewCounts']
        );

    }

    /**
     * 喜欢装备
    */
    public function dolikeGear()
    {
    	if(!$this->uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $gearId = common::request('gearId', 'G');

        $this->load('gear')->likeGear($gearId, $this->uid);
        $this->result['result']['gearId'] = $gearId;
        $this->result['result']['likes'] = $this->load('gear')->getTotalLike($gearId);
    }
    /**
     * 评论
    */
    public function docomment()
    {
    	$uid = $this->uid;
    	if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $gearId = common::request('gearId', 'P');
        $content = common::request('content', 'P');
        $score = common::request('score', 'P',0);
        $fatherId = common::request('fatherId', 'P',0);
        !is_numeric($score) && $score = 0;
        $score > 10 && $score = 10;

        if(!$gearId || empty($content))
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        if(mb_strlen($content,"utf-8")>150){
            $_ENV['error']->getErrors(610);
            exit;
        }

        if ($this->redis->exists(REDIS_PREFIX.'GearComment'.$uid))
        {
          $_ENV['error']->getErrors(607);
          exit();
        }
        if($this->load('badwords')->check($content))
        {
            $_ENV['error']->getErrors(605);
            exit;
        }
        $this->load('gear')->comment($gearId, $content, $score, $uid, $fatherId, array('image', 'images_2', 'images_3'));
    }
    /**
     * 评论列表
    */
    public function docommentList()
    {
        $gearId = common::request('gearId','G', 0);
        $commentId = common::request('commentId','G', 0);
        $direc = common::request('direc','G','next');
        $offset = common::request('offset','G','10');
        $gearInfo = $this->load('gear')->getGearInfo($gearId);
        if(empty($gearInfo) || $gearInfo['isShow'] != 1)
    	{
    		$_ENV['error']->getErrors(1000);
    		exit;
    	}
        $hotComments = $this->load('gear')->hotComments($gearId);
        $allComments = $this->load('gear')->getCommentList($gearId, $commentId, $direc, $offset);
        $totalComments = isset($gearInfo['comments']) ? intval($gearInfo['comments']): 0;
        $this->result['result'] = compact('hotComments', 'allComments', 'total_comment');
    }
    /**
     * 删除评论
     * @return int is_success
     */
    public function dodelComment()
    {
        $commentId = common::request('commentId','G');
        $uid = $this->uid;
        if(!$commentId )
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $this->result['result']['is_success'] = $this->load('gear')->hideComment($uid, $commentId);
    }
    /**
     *  点亮评论
     * @return int is_success
     */
    public function doupComment()
    {
        $commentId = common::request('commentId','G');
        $uid = $this->uid;
        if(!$commentId)
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $this->result['result']['is_success'] = $this->load('gear')->upComment($uid, $commentId);
    }
    /**
     * 装备对比
    */
    public function docompare()
    {
        $firstGear = common::request('first','G');
        $secondGear = common::request('second','G');

        $this->result['result'] = $this->load('gear')->GearCompare(compact('firstGear', 'secondGear'));
    }
    /**
     * 热门搜索词
    */
    public function dohotSearch()
    {
        $this->result['result'] = $this->load('gear')->getHotKeywords();
    }

    /**
     * 筛选选项
     */
    public function dosearchOptions()
    {
        $brands = array();
        $brandList = $this->load('gear')->getBrandList();

        if($brandList)
        {
            foreach($brandList as $brandKey => $brand)
            {
                $brands[] = array(
                    'title' => $brand['brandName'],
                    'img' => $brand['logo'],
                    'value' => $brand['brandName'],
                );
            }
        }

        $this->result['result'] = array(
            array(
                'area_title' => '综合评分',
                'area_param' => 'gearScore',
                'options' => array(
                    array(
                        'title' => '五星',
                        'value' => 5,
                    ),
                    array(
                        'title' => '四星',
                        'value' => 4,
                    ),
                    array(
                        'title' => '三星',
                        'value' => 3,
                    ),
                    array(
                        'title' => '二星',
                        'value' => 2,
                    ),
                    array(
                        'title' => '一星',
                        'value' => 1,
                    ),
                ),
            ),
            array(
                'area_title' => '上市时间',
                'area_param' => 'gearYear',
                'options' => array(
                    array(
                        'title' => '2015',
                        'value' => 2015,
                    ),
                    array(
                        'title' => '2014',
                        'value' => 2014,
                    ),
                    array(
                        'title' => '2013',
                        'value' => 2013,
                    ),
                    array(
                        'title' => '2012',
                        'value' => 2012,
                    ),
                    array(
                        'title' => '2011',
                        'value' => 2011,
                    ),
                ),
            ),
            array(
                'area_title' => '价格',
                'area_param' => 'price',
                'options' => array(
                    array(
                        'title' => '500以下',
                        'value' => '-500',
                    ),
                    array(
                        'title' => '500-600',
                        'value' => '500-600',
                    ),
                    array(
                        'title' => '600-1000',
                        'value' => '600-1000',
                    ),
                    array(
                        'title' => '1000-1500',
                        'value' => '1000-1500',
                    ),
                    array(
                        'title' => '1500以上',
                        'value' => '1500-',
                    ),
                ),
            ),
            array(
                'area_title' => '品牌',
                'area_param' => 'brand',
                'options' => $brands,
            ),
        );
    }
    
    /*
     * 获得渠道信息
     */
    public function dogetChannel(){
        $goods_id = (int)common::request('goods_id','G');
        $gearId = (int)common::request('gearId','G');
        $style_id = (int)common::request('style_id','G');
        $size = common::request('size','G');
        $page = (int)common::request('page','G',1);
        $offset = (int)common::request('offset','G',5)+1;

        
        if(empty($goods_id)&&empty($gearId))
        {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $start = ($page - 1) * $offset;
        
        $sql = "select `supplier_id`,`item_id`,`url`,`name`,description,`pic`,`price`,`sku_colors`,`sku_sizes`, `sku_sizes_str`,`merchant` from r_gear_channel where `merchant` = '淘宝' and `status`=1 and (`gearId` ={$gearId} or goods_id ={$goods_id})";
        $sub_sql = '';
        if($style_id || $size){
            $sub_sql = " and  supplier_id in (select supplier_id from r_gear_channelsize where goods_id=$goods_id";
            if($style_id){
                $sub_sql .= ' and `style_id` = '.$style_id;
            }
            if($size){
                if($size == '35.5'){
                    $sub_sql .=" and size<='$size'";
                }elseif($size == '48'){
                    $sub_sql .=" and size>='$size'";
                }else{
                    $sub_sql .=" and size='$size'";
                }
                
            }
            $sub_sql .= ')';
        }
        $sql .= $sub_sql. " order by price asc limit $start,$offset";

        $rows = $this->db->getAll($sql);
        $has_more = 0;
        if(count($rows) >= $offset){
            $has_more = 1;
            array_pop($rows);
        }

        $gear_mod = $this->load('gear');
        foreach($rows as &$row){
            $row['gearId']  = $gearId;
            $row['url'] = $gear_mod->getGoodsChannelUrlFromH5($row);
            $row['button'] = '购买';
            $row['button_class'] = 'buy';
        }

        //查询推荐数据
        $groupons = null;
        if($style_id==0&&$page==1){
            $groupons = $this->load('gear')->getGrouponByGearId($gearId);
        }

        if($groupons){
            foreach ($groupons as $v) {
                $groupon = array(
                    'istop'=>true,
                    'url'=>"groupondetail?flashId=".$v['id'],
                    'pic'=>$v['image'],
                    'name'=>$v['title'],
                    'description'=>strip_tags($v['image_content']),
                    'price'=>$v['low_price'],
                    'button'=>$v['button']['buy2'],
                    'button_class'=>$v['button']['buy2_class']=='gray' ? 'buy gray' : 'buy',
                );
                if($v['type']==1){
                    $groupon['topname'] = '团购';
                }elseif($v['type']==3){
                    $groupon['topname'] = '推荐';
                }elseif($v['type']==4){
                    $groupon['topname'] = '海淘低价';
                }
                array_unshift($rows,$groupon);
            }
        }
        
        $this->result['result']['goods'] = $rows ? $rows : [];
        $this->result['result']['has_more'] = $has_more;
    }
    
    /*
     * 装备搜索推荐
     */
    public function dosearchSuggest(){
        $keywords = common::request('keywords','G');
        $keywords = trim($keywords);
        //$searcher = $this->load('xunSearch')->init('gear')->getSearcher();
        //->load('xunSearch')->init('gear')->getIndex()->addSynonym('女', 'women');
        //$res =  $this->load('xunSearch')->init('gear')->getSearcher()->getAllSynonyms();
        $res =  $this->load('xunSearch')->init('gear')->getSearcher()->getExpandedQuery($keywords);

        $result = array();
        foreach ($res as $v){
            $result[]= array('name'=>$v);
        }
        $this->result['result'] = array_slice($result,0,4);
        exit;


        if(!$keywords){
            $_ENV['error']->getErrors(101);
            exit;
        }
        
        $gearList = $this->load('gear')->searchSuggest($keywords);
        foreach($gearList as &$v){
            $v['name'] = str_replace(['<em>','</em>'],['<b>','</b>'],$v['name']);
        }
        $this->result['result'] = $gearList;
    }
    /*
    * 购物车添加
    */
    public function doaddshopCart(){
        $uid = $this->uid;
        if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }

        $ogid = common::request('ogid','G');
        $act = common::request('act','G');
        //$flash_id = common::request('aid','G');
        $inshopcart = common::request('inshopcart','G');
        $num = (int)common::request('num','G','1');
        if($num<=0) $num=1;

        $result = true;
        if($act=='del'){
            $result = $this->load('gear')->delshopcart($uid,$ogid);
        }else{
            $result = $this->load('gear')->addshopcart($uid,$ogid,$num,$inshopcart);
        }

        $this->result['result'] = $result;
    }
    /*
    * 我的购物车
    */
    public function domyshopCart(){
        $uid = $this->uid;
        if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $cartList = $this->load('gear')->shopcartlist($uid);
        $this->result['result'] = $cartList;
    }

    /*
    * 检查库存
    */
    public function docheckstock(){
        $ogids = common::request('ogids','G');
        $nums = common::request('nums','G');
        $this->result['result'] =  $this->load('goods')->checkStock($ogids,$nums);
    }

    /*
     * 计算订单价格
     */
    public function docalculateOrderPrices(){
        print_r($this->load('shihuo')->updateDaigouPrice(274509));

        $this->printResult = false;
        exit;
    }

    /*
     * 海淘订单状态变更
     */
    public function dohaitaoorderchange(){
        $this->printResult = false;
        $orderid = common::request('order_id','P');
        $token = common::request('token','P');
        $result  = false;
        if(md5("*#06#mc".$orderid)==$token){
            $orderinfo = $this->load('shihuo')->getOrderInfo($orderid);
            $result = $this->load('order')->updateHaitaoOrderStatus($orderinfo);
        }
        echo json_encode(array('status'=>$result?'success':'fail'));
    }

    /*
     * 添加身份证
     */
    public function doaddusercardid(){
        $uid = $this->uid;
        if(!$uid)
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $cardid = common::request('cardid','');
        $result = $this->db->insertRowTable('r_user_ext',array(
            'cardid'=>$cardid,
            'uid' =>$uid
            ));
        $this->result['result'] = $result;
    }


}